<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <base th:href="@{/}">
    <meta charset="UTF-8">
    <title>病人列表主页</title>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/style1.css" rel="stylesheet">
    <link href="/css/style.css" rel="stylesheet">
    <script src="/js/jquery.min.js"></script>
    <script type="text/javascript" th:inline="javascript">
        function deleteUser(tid) {
            $.ajax({
                url: [[@{/user/delete}]],
            type: "post",
                data: {
                id: tid
            },
            success: function (obj) {
                if (obj == "no") {
                    alert("该病人有关联不允许删除！");
                } else {
                    alert(obj);
                    // 并刷新网页
                    location.reload();
                }
            },
            error: function () {
                alert("处理异常！");
            }
        });
        }
    </script>
</head>
<body>
<div th:include="admin/header1"></div>
<main id="main">
    <section class="breadcrumbs">
        <div class="container">
            <div class="d-flex justify-content-between align-items-center">
                <ol>
                    <li><a href="#">首页</a></li>
                    <li><a href="#">病人列表管理</a></li>
                </ol>
            </div>
        </div>
    </section>
    <section class="inner-page">
        <div class="container" id="contentArea">
            <div class="card">
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table text-center">
                        <thead>
                        <tr>
                            <th>病人编号</th>
                            <th>病人的名字</th>
                            <th>病人性别</th>
                            <th>余额</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="user : ${allUsers}">
                            <td th:text="${user.id}"></td>
                            <td th:text="${user.name}"></td>
                            <td th:text="${user.sex}"></td>
                            <td th:text="${user.balance}"></td>
                            <td>
                                <form th:action="@{/user/detail(id=${user.id})}" method="post" style="display: inline">
                                    <button type="submit" class="btn btn btn-sm">详情</button>
                                </form>
                                <form th:action="@{/user/toUpdate(id=${user.id})}" method="post" style="display: inline">
                                    <button type="submit" class="btn btn1 btn-sm">修改</button>
                                </form>
                                <a th:href="'javascript:deleteUser(' + ${user.id} + ')'" class="btn btn2 btn-sm" style="margin-left: 20px;">删除</a>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="5" style="border: none;">
                                <ul class="pagination justify-content-center">
                                    <li class="page-item" th:if="${currentPage}!= 1">
                                        <a class="page-link"
                                           th:href="@{/user/selectAllUsersByPage(currentPage=${currentPage - 1})}">上一页</a>
                                    </li>
                                    <li class="page-item disabled">
                                        <a class="page-link" href="#">第<span
                                                th:text="${currentPage}"></span>页</a>
                                    </li>
                                    <li class="page-item disabled">
                                        <a class="page-link" href="#">共<span
                                                th:text="${totalPage}"></span>页</a>
                                    </li>
                                    <li class="page-item" th:if="${currentPage}!= ${totalPage}">
                                        <a class="page-link"
                                           th:href="@{/user/selectAllUsersByPage(currentPage=${currentPage + 1})}">下一页</a>
                                    </li>
                                </ul>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </section>
</main>
<script src="js/main.js"></script>
</body>

</html>